/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package slicktemplate;

import java.util.ArrayList;
import org.newdawn.slick.geom.Shape;

/**
 *
 * @author andrew
 */
public class Collideable {

    Shape boundingBox;

    boolean getCollision(Shape otherShape) {
        return otherShape.intersects(boundingBox);
    }

    boolean getCollision(float x, float y) {
        return boundingBox.contains(x, y);
    }
    
    boolean isBuilding() {
        return false;
    }

    static boolean getCollision(Shape self, ArrayList<Collideable> otherShapes) {
        for (Collideable other : otherShapes) {
            if (other.getCollision(self) && (self != other.getShape())) {
                return true;
            }
        }
        return false;
    }

    static Object getCollisionObject(Shape self, ArrayList<Collideable> otherShapes) {
        for (Collideable other : otherShapes) {
            if (other.getCollision(self) && (self != other.getShape())) {
                return other;
            }
        }
        return null;
    }

    static Object getCollisionObjects(Shape self, ArrayList<Collideable> otherShapes) {
        ArrayList objs = new ArrayList();
        for (Collideable other : otherShapes) {
            if (other.getCollision(self) && (self != other.getShape())) {
                objs.add(other);
            }
        }
        return objs;
    }

    static boolean getCollisionLists(Shape self, ArrayList<ArrayList> otherLists) {
        for (int i = 0; i < otherLists.size(); i++) {
            ArrayList lists = otherLists.get(i);
            for (int j = 0; j < lists.size(); j++) {
                Collideable other = (Collideable) lists.get(j);
                if (other.getCollision(self)) {
                    if (self != other.getShape()) {
                        return true;
                    }
                }
            }

        }
        /* for (ArrayList<Collideable> lists : otherLists) {
        for (Collideable other : lists) {
        Collideable other = lists.get(j);
        if (other.getCollision(self)) {
        if (self != other.getShape()) {
        return true;
        }
        }
        }
        }*/
        return false;
    }

    static boolean getContainsLists(Shape self, ArrayList<ArrayList> otherLists) {
        for (ArrayList<Collideable> lists : otherLists) {
            for (Collideable other : lists) {
                if (other.getShape().contains(self)) {
                    if (self != other.getShape()) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    static Object getCollisionListsObject(Shape self, ArrayList<ArrayList> otherLists) {
        for (ArrayList<Collideable> lists : otherLists) {
            for (Collideable other : lists) {
                if (other.getCollision(self) && (self != other.getShape())) {
                    return other;


                }
            }
        }
        return null;
    }

    static ArrayList<Collideable> convertToCollidable(ArrayList change) {
        ArrayList<Collideable> cd = new ArrayList<Collideable>();

        for (int i = 0; i
                < change.size(); i++) {
            cd.add((Collideable) change.get(i));
        }
        return cd;
    }

    private Shape getShape() {
        return boundingBox;

    }
}
